package cn.com.huzo.webapp.controller.admin;

import huzofw.common.web.controller.BaseFormController;
import huzofw.service.security.EventLogManager;
import java.sql.Timestamp;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 操作日志控制器
 *
 * @author 吴旭
 */
@Controller
public class EventLoggerController extends BaseFormController {

    // <editor-fold defaultstate="collapsed" desc="属性部分">
    @Resource(name = "EventLogManager")
    private EventLogManager _logManager;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="画面处理部分">
    /**
     * 跳转到操作日志一览画面
     * <p>
     * @return
     */
    @RequestMapping("admin/event_log/list.html")
    public ModelAndView redirectListWnd() {
        ModelAndView view = new ModelAndView();
        view.setViewName("admin.event_log.list.def");
        return view;
    }

    /**
     * 弹出日志数据整理条件画面
     * <p>
     * @return
     */
    @RequestMapping("admin/event_log/clean.html")
    public ModelAndView redirectCleanEventLogOptionPopupWnd() {
        ModelAndView view = new ModelAndView();
        view.setViewName("popup.admin.event_log.clean.def");
        return view;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="数据处理部分">
    /**
     * 根据条件取得操作日志分页数据。
     * <p>
     * @param criterion 检索条件
     * @return 操作日志分页数据
     * @throws Exception
     */
    @RequestMapping(value = "admin/event_log/fetchForPage.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> fetchForPage(@RequestBody Map<String, Object> criterion) throws Exception {
        return _logManager.fetchForPage(criterion);
    }

    /**
     * 删除操作日志。
     *
     * @param timePoint 删除的时间点
     * @return 影响行数
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "admin/event_log/delete.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Integer deleteData(@RequestBody final Timestamp timePoint) throws Exception {
        return _logManager.Delete(timePoint);
    }
    // </editor-fold>
}
